﻿using GrapeCity.Forguncy.CellTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Vant.CellTypes;

namespace Vant.WpfControls.DrawingObject
{
    /// <summary>
    /// Interaction logic for RateDrawingObject.xaml
    /// </summary>
    public partial class RateDrawingObject : UserControl
    {
        public RateDrawingObject(Rate rate, IDrawingHelper drawingHelper)
        {
            var viewModel = new RateDrawingObjectViewModel();

            for (int i = 0; i < rate.iconCount; i++)
            {
                viewModel.Items.Add(new Item()
                {
                    Icon = i < 3 ? IconHelper.GetBuiltInIcon("starOn", drawingHelper, GetSelectColor(rate)) : IconHelper.GetBuiltInIcon("starOff", drawingHelper, GetUnSelectColor(rate)),
                    Size = rate.iconSize,
                    Margin = i == rate.iconCount - 1 ? new Thickness(0) : new Thickness(0, 0, rate.iconGutter, 0)
                });
            }

            this.DataContext = viewModel;
            InitializeComponent();
        }

        private string GetSelectColor(Rate rate)
        {
            if (rate.IsDisabled)
            {
                return rate.disabledColor;
            }
            return rate.color;
        }
        private string GetUnSelectColor(Rate rate)
        {
            if (rate.IsDisabled)
            {
                return rate.disabledColor;
            }
            return rate.voidColor;
        }

        public RateDrawingObjectViewModel ViewModel
        {
            get
            {
                return this.DataContext as RateDrawingObjectViewModel;
            }
        }

        public class RateDrawingObjectViewModel : ModelBase
        {
            public List<Item> Items { get; set; } = new List<Item>();
        }

        public class Item
        {
            public object Icon { get; set; }
            public double Size { get; set; }
            public Thickness Margin { get; set; }
        }
    }
}
